package com.ruoyi.business.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.JtPaymentAccount;
import com.ruoyi.business.service.IJtPaymentAccountService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 支付账号Controller
 * 
 * @author Alan Zhang
 * @date 2025-05-22
 */
@Controller
@RequestMapping("/payment/account")
public class JtPaymentAccountController extends BaseController
{
    private String prefix = "payment/account";

    @Autowired
    private IJtPaymentAccountService jtPaymentAccountService;

    @RequiresPermissions("payment:account:view")
    @GetMapping()
    public String account()
    {
        return prefix + "/account";
    }

    /**
     * 查询支付账号列表
     */
    @RequiresPermissions("payment:account:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JtPaymentAccount jtPaymentAccount)
    {
        startPage();
        List<JtPaymentAccount> list = jtPaymentAccountService.selectJtPaymentAccountList(jtPaymentAccount);
        return getDataTable(list);
    }

    /**
     * 导出支付账号列表
     */
    @RequiresPermissions("payment:account:export")
    @Log(title = "支付账号", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JtPaymentAccount jtPaymentAccount)
    {
        List<JtPaymentAccount> list = jtPaymentAccountService.selectJtPaymentAccountList(jtPaymentAccount);
        ExcelUtil<JtPaymentAccount> util = new ExcelUtil<JtPaymentAccount>(JtPaymentAccount.class);
        return util.exportExcel(list, "支付账号数据");
    }

    /**
     * 新增支付账号
     */
    @RequiresPermissions("payment:account:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存支付账号
     */
    @RequiresPermissions("payment:account:add")
    @Log(title = "支付账号", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JtPaymentAccount jtPaymentAccount)
    {
        return toAjax(jtPaymentAccountService.insertJtPaymentAccount(jtPaymentAccount));
    }

    /**
     * 修改支付账号
     */
    @RequiresPermissions("payment:account:edit")
    @GetMapping("/edit/{accountId}")
    public String edit(@PathVariable("accountId") Long accountId, ModelMap mmap)
    {
        JtPaymentAccount jtPaymentAccount = jtPaymentAccountService.selectJtPaymentAccountByAccountId(accountId);
        mmap.put("jtPaymentAccount", jtPaymentAccount);
        return prefix + "/edit";
    }

    /**
     * 修改保存支付账号
     */
    @RequiresPermissions("payment:account:edit")
    @Log(title = "支付账号", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JtPaymentAccount jtPaymentAccount)
    {
        return toAjax(jtPaymentAccountService.updateJtPaymentAccount(jtPaymentAccount));
    }

    /**
     * 删除支付账号
     */
    @RequiresPermissions("payment:account:remove")
    @Log(title = "支付账号", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jtPaymentAccountService.deleteJtPaymentAccountByAccountIds(ids));
    }
}
